<?php
namespace App\Models\Chain\InviteCash;




use App\Helpers\Utils;
use App\Models\Chain\InviteCash\CreateAccountLogAction;
use App\Models\Factory\InviteFactory;
use App\Models\Chain\AbstractHandler;
use App\Models\Orm\AwUserInviteCash;

/**
 * 插入用户邀请得现金表
 * Class CreateCreditLogAction
 * @package App\Models\Chain\Identity
 */

class CreateInviteCashAction extends AbstractHandler
{
    private $params = array();

    protected $error = array('error' => '插入积分日志失败', 'code' => 7011);


    public function __construct($params)
    {
        $this->params = $params;
    }

    public function handleRequest()
    {

        if ($this->CreateInviteCash($this->params) == true) {
            $this->setSuccessor(new UpdateUserAccountAction($this->params));
            return $this->getSuccessor()->handleRequest();
        } else {
            return $this->error;
        }
    }


    public function CreateInviteCash($params)
    {
        //通过被邀请人id拿到y邀请人id


        // 生成提现记录
        $insert_data = [
            'user_id' => $params['user_id_invite'],
            'money' => AwUserInviteCash::INVITE_CASH,
            'status' => AwUserInviteCash::STATUS_INIT,
            'ip' => strval(ip2long(Utils::ipAddress())),
        ];

        $cash_id = AwUserInviteCash::insertGetId($insert_data);

        $params['cash_id'] =  $cash_id;
        $this -> params = $params;

        return true;

    }


}